<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
	<title><%=ProConfig.PROJECT_NAME %></title>
	<%@ include file="/WEB-INF/wechat/iot/common/resource_lib.jsp"%>
	<style type="text/css">
		.sub-container{
			margin-left: 10px;
			padding: 10px 10px 10px 0;
			border-top: 1px solid #d9d9d9;
		}
		
		.sub-container:FIRST-CHILD{
			border-top: 0;
		}
		
		.body-container{
			background: #fff ;
		}
		.sub-container p{
			font-size: 14px;
		}
	</style>
</head>
<body>
	<div class="container">
		<div class="t-c title-info">
			<span>Device list</span>
			<div class="back" onclick="forward('/wiot/mscene')" style=" position: fixed;top: 0px;" >Back</div>
			<c:if test="${user.type == 10 || user.type == 8 }">
				<div class="add" onclick="addDevice()" style=" position: fixed;top: 0px;right: 10px;" >Bind device</div>
			</c:if>
		</div>
		<div style="height: 50px;"></div>
		
		<div class="body-container">
			
		</div>
		
		<%@ include file="/WEB-INF/wechat/iot/common/pager.jsp"%>
		
		<div id="template" class="hide">
			<div class="sub-container clear" 
			   <c:if test="${user.type == 10 || user.type == 8 }">
			   onclick="deviceInit({id})"
			   </c:if>
			   >
				<div class="float-left width50">
					<p class="title" style="color: #333;">
						<span class="state" style="margin-left: 0;">{name}</span>
					
					</p>
					<p style="color: #666;padding-top: 10px;">{atimestr}</p>
				</div>
				<div class="float-left width50 " style="text-align: left;">
					<p style="color: #666;">
						status： {data.iot_node_status}
					</p>
					<p style="color: #666;padding-top: 10px;">SN: {device_code}</p>
				</div>
			</div>
		</div>
	</div>
	
	
</body>
<script type="text/javascript">
	function addDevice(){
		forward('/wiot/edevice?id=' + GetQueryString("id") );
	}
	
	function deviceInit(did){
		$.actions({
			  actions: [
// 				  {
// 			    text: "编辑",
// 			    className: "color-success",
// 			    onClick: function() {
// 			     	forward("/wiot/edevice?id="+GetQueryString("id") +"&did=" +did );
// 			    }
// 			  },
			  {
			    text: "delete",
			    className: "color-danger",
			    onClick: function() {
			    	
			    	$.confirm("Do you confirm deletion?", function() {
			    		commonAjax("DELETE",localUrl+"/node?id="+ did  , "",function(){
							tip("Successfully deleted");
							setTimeout(function(){
								window.location.reload();
							},200)
				    	})
					  }, function() {
					  
					  });
			    	
			    }
			  }]
			});
	}
	
	$(function(){
		
		//查询条件
		var data =  {scene_id:GetQueryString("id")} ;
		var paged = 1;
		getData(paged++);
		var loading = false;  //状态标记
		$(document.body).infinite().on("infinite", function() {
			if (loading)
				return;
			loading = true;
			setTimeout(function() {
				// 获取商品信息
				getData(paged++);
			}, 500); 
		});

		function getData(paged){
			var sid = GetQueryString("id") ;
			postAjax(localUrl+"/page/node/sensor/lists.json?pageSize=6&paged="+paged , data ,function(data){
				if(isOK(data)){
					var dataObj = data.data.data ;
					for(var i=0; i <dataObj.length;i++){
						 dataObj[i].atimestr = time2Str(dataObj[i].atime,'yyyy/MM/dd hh:mm');
						 dataObj[i].device_code = disvalue(dataObj[i].device_code,20);
						$(".body-container").append($("#template").html().format( dataObj[i]));
					}
					if(data.data.totalPage > data.data.paged){
						loading = false;						
					}else{
						loading =true ;	
					}
				}else{
					loading =true ;	
				}
				// 传data就可以，分页的
				pagerinit(data,".body-container");
			});
		}
		
	})
</script>
</html>